package com.mybook.allbook.controller;

import com.mybook.allbook.entity.Emp;
import com.mybook.allbook.entity.User;
import com.mybook.allbook.service.EmpService;
import com.mybook.allbook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;
    @Autowired
    private UserService userService;
    @PostMapping("/update")
    public String update(Emp emp){
        empService.update(emp);
        return "redirect:/emp/findAll";
    }


    @GetMapping("/find")
    public String find(String id,Model model){
        Emp emp = empService.find(id);
        model.addAttribute("emp",emp);
        return "/ems/updateEmp";
    }


    @PostMapping("/save")
    public String save(Emp emp){
        empService.save(emp);
        return "redirect:/emp/findAll";
    }


    @GetMapping("/findAll")
    public String findAll(Model model){
        List<Emp> emps = empService.findAll();
        model.addAttribute("emps",emps);
        return "/ems/emplist";
    }

    @GetMapping("/findAll2")
    public String findAll2(Model model){
        List<Emp> emps = empService.findAll();
        model.addAttribute("emps",emps);
        return "/ems/user";
    }



    @GetMapping("/findAll3")
    public String findAll3(Model model){
        List<User> users = userService.findAll();
        model.addAttribute("users",users);
        return "/ems/report";
    }


    @GetMapping("/delete")
    public String delete(String id){
        empService.delete(id);
        return "redirect:/emp/findAll";
    }

    @GetMapping("/mytime")
    public String mytime1(){

        return "/ems/shizhong";
    }

    @GetMapping("/web")
    public String web(){

        return "/ems/Web";
    }

    @GetMapping("/kefu")
    public String kefu(){

        return "/ems/kefu";
    }

}
